1
|
|
|
import BaseCard from './BaseCard'; |
2
|
|
|
import {chat_v1 as chatV1} from '@googleapis/chat'; |
3
|
|
|
import {LocaleTimezone, PollState} from '../helpers/interfaces'; |
4
|
|
|
import {generateHelperWidget} from '../helpers/helper'; |
5
|
|
|
import {createButton} from '../helpers/cards'; |
6
|
|
|
|
7
|
|
|
export default class ClosePollFormCard extends BaseCard { |
8
|
|
|
id = 'close_poll_form'; |
9
|
|
|
state: PollState; |
10
|
|
|
timezone: LocaleTimezone; |
11
|
|
|
|
12
|
|
|
constructor(config: PollState, timezone: LocaleTimezone) { |
13
|
|
|
super(); |
14
|
|
|
this.state = config; |
15
|
|
|
this.timezone = timezone; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
create(): chatV1.Schema$GoogleAppsCardV1Card { |
19
|
|
|
this.buildHeader(); |
20
|
|
|
if (this.state.closedTime) { |
21
|
|
|
this.buildCurrentScheduleInfo(); |
22
|
|
|
} |
23
|
|
|
this.buildButtons(); |
24
|
|
|
this.buildSections(); |
25
|
|
|
return this.card; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
buildHeader() { |
29
|
|
|
this.card.header = { |
30
|
|
|
'title': 'Are you sure to close the poll?', |
31
|
|
|
'subtitle': 'No one will have the ability to vote.', |
32
|
|
|
'imageUrl': '', |
33
|
|
|
'imageType': 'CIRCLE', |
34
|
|
|
}; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
buildCurrentScheduleInfo() { |
38
|
|
|
const locale = this.timezone.locale; |
39
|
|
|
const closedDate = new Date(this.state.closedTime!).toLocaleString(locale, {timeZone: this.timezone.id}); |
40
|
|
|
this.card.sections!.push( |
41
|
|
|
{ |
42
|
|
|
'widgets': [ |
43
|
|
|
{ |
44
|
|
|
'decoratedText': { |
45
|
|
|
'text': `<i>This poll already has Auto Close schedule at <time> ${closedDate}</time>(${this.timezone.id}) </i>`, |
46
|
|
|
'startIcon': { |
47
|
|
|
'knownIcon': 'CLOCK', |
48
|
|
|
'altText': '@', |
49
|
|
|
}, |
50
|
|
|
}, |
51
|
|
|
}, |
52
|
|
|
], |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
buildButtons() { |
57
|
|
|
let scheduleButtonText = 'Create Schedule Close'; |
58
|
|
|
if (this.state.closedTime) { |
59
|
|
|
scheduleButtonText = 'Edit Schedule Close'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
this.addSectionWidget({ |
63
|
|
|
'buttonList': { |
64
|
|
|
'buttons': [ |
65
|
|
|
createButton(scheduleButtonText, 'schedule_close_poll_form'), |
66
|
|
|
createButton('Close Now', 'close_poll'), |
67
|
|
|
], |
68
|
|
|
}, |
69
|
|
|
}); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
buildSections() { |
73
|
|
|
this.card.sections!.push(generateHelperWidget()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|